Visualizing the Environmental Impact of Beef Consumption using Plotly and Shiny

Elizabeth Sweeney, ScM, PhD Assistant Professor, Biostatsitics Weill Cornell @emsweene57

November 9, 2019

Who Am I?

Who Am I?


Who Am I?


Happy Valley Meat Company


Happy Valley Meat Company


Happy Valley Meat Company works with some pretty well known restaurants…


Momofuku Ko

Momofuku Ssam Bar

The Dutch

Dig Inn

Fette Sau

Frenchette

Happy Valley Meat Company


The Data

The weight of each cut of meat on one beef animal:

cut total_weight
Blended Burger 379
Ground Beef 250
Beef Trimmings 250
Beef Patties 250
Fat 100
Bones 80
Round 64
Chuck Roll 60
Bone-in Ribeye 48
Bone-in Strip 36

The Data

The Data

The Data

##constants
water.rate <- 6.36 #(million gallons of water per 1 animal) 
co2.emision <- 102.96 #(thousand lbs of co2 emissions per 1 animal) 
land.use <- 77 #(acres of land per 1 animal)


Source: Ranganathan, Janet, et al. “Shifting diets for a sustainable food future.” World Resources Institute (2016).

The Data

##load in the dplyr library
library(dplyr)

##entry weight for pound of meat
weight = 100

## calculations for enviornmental impact  
carcass_calculator_data_100_pounds <- carcass_calculator_data %>%
  mutate(number_cows = ceiling(weight/total_weight)) %>% 
  select(-total_weight)

The Data

The number of beef animals required for 100 pounds of each cut:

cut number_cows
Blended Burger 1
Ground Beef 1
Beef Trimmings 1
Beef Patties 1
Fat 1
Bones 2
Round 2
Chuck Roll 2
Bone-in Ribeye 3
Bone-in Strip 3

The Data

##calculate the enviornmental impact 
carcass_calculator_data_100_pounds <- carcass_calculator_data_100_pounds %>% 
  mutate(water_rate = water.rate * number_cows) %>% 
  mutate(co2_emission = co2.emision * number_cows) %>% 
  mutate(land_use = land.use * number_cows) 

The Data

The enviornmental impact for 100 pounds of each of the following cuts:

cut number_cows water_rate co2_emission land_use
Blended Burger 1 6.36 102.96 77
Ground Beef 1 6.36 102.96 77
Beef Trimmings 1 6.36 102.96 77
Beef Patties 1 6.36 102.96 77
Fat 1 6.36 102.96 77
Bones 2 12.72 205.92 154
Round 2 12.72 205.92 154
Chuck Roll 2 12.72 205.92 154
Bone-in Ribeye 3 19.08 308.88 231
Bone-in Strip 3 19.08 308.88 231

Animal Lives

## load in the required the packages 
library(ggplot2)
library(wesanderson)

##create a color palette
values=wes_palette(n=4, name="Darjeeling1")

##reorder the data in order of number of cows 
plot.data <- carcass_calculator_data_100_pounds %>% 
  mutate(cut = reorder(cut, number_cows))

##plot th data in a barplot 
plot.out <- ggplot(plot.data, 
                   aes(x = cut, 
                       y = number_cows)) + 
  geom_bar(stat="identity", fill = values[4]) + 
  coord_flip() + 
  xlab('') + 
  ylab('Animals') + 
  theme(legend.position="none",
        axis.title=element_text(size=12),
        plot.title=element_text(size = 16)) + 
  ggtitle(paste0('Animals for ', weight, ' Pounds of Meat by Cut'))

Animal Lives

Animal Lives

Animal Lives

The %+% function allows you to replace the data frame that you are using with ggplot!

## make a vector of a subset of the cuts  
cut.list <- c('Tongue',
              'Ground Beef',
              'Tenderloin',
              'Bone-in Ribeye',
              'Skirt')

## plot the data for the subset of the cuts
plot.out %+% filter(plot.data, cut %in% cut.list) + 
  theme(axis.text=element_text(size=14))

Animal Lives

Animal Lives

library(plotly)
ggplotly(plot.out, tooltip = c("x", "y"))

Animal Lives

Animal Lives

Co2 Emissions

Water Usage

Land Usage

Plot All Together

Plot All Together

Other Plotly Projects: Hiking Trails


Other Plotly Projects: Hiking Trails


Other Plotly Projects: Hiking Trails

Lat Lng Distance..miles. Elevation..feet.
42.13400 -74.10404 0.0000000 2054
42.13383 -74.10510 0.0556631 2073
42.13324 -74.10629 0.1288833 2060
42.13232 -74.10648 0.1928586 2067
42.13137 -74.10583 0.2669656 2077
42.13041 -74.10542 0.3368528 2100

Other Plotly Projects: Hiking Trails

x <- list(
  title = "Distance (in miles)"
)

y <- list(
  title = "Elevation (in feet)"
)

plot_ly(data = devils.path,
        x = ~Distance..miles.,
        y = ~Elevation..feet.,
        type = 'scatter', 
        mode = 'lines',
        color = I('purple'),
        hoverinfo = 'text',
        text = paste(
          round(devils.path$Distance..miles., 1), 
          "miles, ",                    
          round(devils.path$Elevation..feet., 0),
          "feet elevation"),
        fill = 'tozeroy')  %>%
  layout(xaxis = x, 
         yaxis = y,
         title = "The Devil's Path",
         shapes=list(type='line', 
                     y0= 3500, 
                     y1= 3500, 
                     x0=min(devils.path$Distance..miles.),
                     x1=max(devils.path$Distance..miles.),
                     line=list(dash='dot', width=1)))

Other Plotly Projects: Hiking Trails

Shiny App!

https://emsweene.shinyapps.io/carcass_calculator_4/